package restaurant;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * A item on the menu.
 *
 * @author larsonmp
 */
@Entity
public class MenuItem implements Serializable {
	private static final long serialVersionUID = 201212021603L;

	@Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;

    @Basic
    private Integer number;

    @Basic
    private String name;

    @Basic
    private String description;

    @Basic
    private Float price;

    @Basic
    private String modifier;

    @ManyToOne
    private MenuCategory category;

    @OneToMany
    private List<Tag> tags = new ArrayList<>();

    public MenuItem() { }

    public MenuItem(final Integer id, final String name) {
        this.id = id;
        this.name = name;
    }

    public MenuItem(final Integer id, final String name, final Integer number, final String description, final Float price,
            final MenuCategory category, final List<Tag> tags) {
        this.id = id;
        this.name = name;
        this.number = number;
        this.description = description;
        this.price = price;
        this.category = category;
        this.tags = tags;
    }

    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(final Integer id) {
        this.id = id;
    }

    /**
     * @return the number
     */
    public Integer getNumber() {
        return number;
    }

    /**
     * @param number the number to set
     */
    public void setNumber(final Integer number) {
        this.number = number;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(final String name) {
        this.name = name;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(final String description) {
        this.description = description;
    }

    /**
     * @return the price
     */
    public Float getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(final Float price) {
        this.price = price;
    }

    /**
     * @return the category
     */
    public MenuCategory getCategory() {
        return category;
    }

    /**
     * @param category the category to set
     */
    public void setCategory(final MenuCategory category) {
        this.category = category;
    }

    /**
     * @return the modifier
     */
    public String getModifier() {
        return modifier;
    }

    /**
     * @param modifier the category to set
     */
    public void setModifier(final String modifier) {
        this.modifier = modifier;
    }

    /**
     * @return the tags
     */
    public List<Tag> getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(final List<Tag> tags) {
        this.tags = tags;
    }

    public void addTag(final Tag tag) {
        this.tags.add(tag);
    }

    @Override
    public String toString() {
        return String.format("[0x%08x] %s > %s ($%1.2f): %s",
                hashCode(), getCategory().getName(), getName(), getPrice(), getDescription());
    }
}
